package com.example.shengyin.service;

import com.example.shengyin.dao.CityMapper;
import com.example.shengyin.entity.City;
import com.example.shengyin.entity.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CityService {

    @Autowired
    private CityMapper dao;

    public List<City> selectById(Long id){
        return dao.selectById(id);
    }

    // 根据name查其id
    public Long selectIdByName(@Param("name") String name){
        return dao.selectIdByName(name);
    }

    // 根据parentid查上级的name
    public String selectNameByParentid(@Param("parentid")Long parentid){
        return dao.selectNameByParentid(parentid);
    }

    //根据id查id所对应的省份名
    public String selectParentNameById(@Param("id")Long id){
        return dao.selectParentNameById(id);
    }


    public City select(@Param("id") Long id){
        return dao.select(id);
    }


    public List<City> list(Page page, String name){
        return dao.list((page.getPage()-1)*page.getLimit(),page.getLimit(),name);
    }


    public int insert(City city){
        return dao.insert(city);
    }

    public int update(City city){
        return dao.update(city);
    }


    public int delete(@Param("id") int id){
        return dao.delete(id);
    }

    public int count(@Param("name") String name){
        return dao.count(name);
    }

    public int deleteByIds(@Param("ids") String ids){
        return dao.deleteByIds(ids);
    }
}
